package com.allinpokers.vest.allinvest.model.respon;

import com.allinpokers.vest.allinvest.enu.ResponseCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "数据返回")
public class CommonRespon<T> {
    @ApiModelProperty(value = "返回码", example = "1")
    protected Integer code = ResponseCodeEnum.SUCCESS.getCode();
    @ApiModelProperty(value = "返回消息", example = "成功")
    protected String msg = ResponseCodeEnum.SUCCESS.getMsg();
    @ApiModelProperty(value = "数据", example = "")
    protected T data;

    public  boolean isSuccess() {
        return this.code.equals(ResponseCodeEnum.SUCCESS.getCode());
    }

    public static <T> CommonRespon<T> success() {
        return success(null);
    }
    public static <T> CommonRespon<T> success(String msg) {
        CommonRespon<T> resp = new CommonRespon<>();
        resp.setMsg(msg);
        return resp;
    }
    public static <T> CommonRespon<T> success(T data) {
        CommonRespon<T> resp = new CommonRespon<>();
        resp.setData(data);
        return resp;
    }

    public static <T> CommonRespon<T> failure(ResponseCodeEnum code) {
        CommonRespon<T> resp = new CommonRespon<>();
        resp.setCode(code.getCode());
        resp.setMsg(code.getMsg());
        return resp;
    }

    public static <T> CommonRespon<T> failure(ResponseCodeEnum code,String msg) {
        CommonRespon<T> resp = new CommonRespon<>();
        resp.setCode(code.getCode());
        resp.setMsg(msg);
        return resp;
    }

    public static <T> CommonRespon<T> failure(int code,String msg) {
        CommonRespon<T> resp = new CommonRespon<>();
        resp.setCode(code);
        resp.setMsg(msg);
        return resp;
    }
}
